package com.espirit.builder.biz;

import org.springframework.stereotype.Component;

import com.espirit.eap.manager.ModelBuilderSupport;
import com.espirit.eap.manager.workflow.WFInstance;
import com.espirit.eap.pagelayout.ModelField;
import com.googlecode.cswish.annotation.Dependence;


@Dependence({
	"com.espirit.builder.biz.WFPhaseBuilder",
	"com.espirit.builder.biz.WFTemplateBuilder"
})
@Component
public class WFInstanceBuilder extends ModelBuilderSupport {

	private static final String FIELD_TEMPLATENAME = "wfTemplate.name";
	private static final String FIELD_CURRENTPHASE = "wfPhase.name";
	private static final String FIELD_DESCRIPTION ="description";
	private static final String FIELD_CREATEDON ="createdOn";
	private static final String FIELD_STATUS = "status";
	
	private static final String FIELD_TEMPLATEID = "wfTemplate.id";
//	private static final String FIELD_EVENTID = "event.id";
	private static final String FIELD_SRCID = "srcId";
	private static final String FIELD_SRCCLASSNAME = "srcClassName";
	
	@Override
	public boolean init() {
		return super.setClass(WFInstance.class, "Instance", "Instance") ;
	}
	
	@Override
	public void buildFields() {
		addModelField(FIELD_TEMPLATENAME, "Template Name", "模板");
		addModelField(FIELD_CURRENTPHASE, "Phase Name", "阶段");
		addModelField(FIELD_STATUS, "Decide", "决定");
		addModelField(FIELD_DESCRIPTION, "Description", "备注");
		
		addModelField(FIELD_SRCID, "Source ID", "Source ID");
		addModelField(FIELD_SRCCLASSNAME, "Source Class Name", "Source Class Name");
		
	}
	
	@Override
	public void prepareLayoutElements() {
		ModelField mfTemplateName = getModelField(FIELD_TEMPLATENAME);
		ModelField mfPhase = getModelField(FIELD_CURRENTPHASE);
		ModelField mfDescription = getModelField(FIELD_DESCRIPTION);
		ModelField mfCreatedOn = getModelField(FIELD_CREATEDON);
		
		ModelField mfTemplateID = getModelField(FIELD_TEMPLATEID);
		ModelField mfSrcId = getModelField(FIELD_SRCID);
		
		addListField(mfTemplateName,mfPhase,mfCreatedOn,mfDescription);
		addDetailField(mfTemplateName,mfCreatedOn,mfDescription,mfTemplateID,mfSrcId ,getModelField(FIELD_SRCCLASSNAME));
		safeElement(detailElements, FIELD_TEMPLATENAME).setReadOnly(true);
		safeElement(detailElements, FIELD_CREATEDON).setReadOnly(true);
		safeElement(detailElements, FIELD_DESCRIPTION).setTagName("textarea");
		
		super.prepareLayoutElements();
	}
	
	@Override
	protected void afterBuilderLayout() {
		super.afterBuilderLayout();
	}
	
	@Override
	protected Integer getDetailLayoutSectionColsPerRow() {
		return 1;
	}
}
